package service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;


import pojo.pic;


import base.BaseService;
public class PictureService extends  BaseService{
	 public class PictureRowMapper implements RowMapper<pic> {
			
  	   public pic mapRow(ResultSet rs, int rownum) throws SQLException {
  
	pic inf = new pic();
	inf.setId(rs.getInt("id"));
    inf.setTopic(rs.getString("topic"));
    inf.setDetail(rs.getString("detail"));
    inf.setPic(rs.getString("pic"));
	inf.setTime(rs.getDate("time"));
	return inf;
			}
     }
	 public int getALL(){
			String sql = "SELECT count(*) FROM picture ";
			
			int count1 = this.jdbcTemplate.queryForInt(sql);
			
			return count1;
			
		}
		public List<pic> getpic(){
				String sql = "SELECT * from picture ";
				return jdbcTemplate.query(sql,new PictureRowMapper());
		}

		 public int DeleteP(int id){
				
				String sql ="delete from picture where id=?";
				
				return jdbcTemplate.update(sql,id);
				
		 }	
		 public int add(String topic,String detail,String pic){
			 Timestamp time=new Timestamp(System.currentTimeMillis());
				String sql ="insert into picture(topic,detail,pic,time) values(?,?,?,?)";
				
				return jdbcTemplate.update(sql,topic,detail,pic,time);
			}
}
